package com.erpanderp.wam.ac.model.service.project;

import java.util.List;

import org.hibernate.FlushMode;
import org.hibernate.Query;
import org.hibernate.Session;
import com.erpanderp.wam.ac.model.entity.project.ProjectAssignmentDetail;
import com.erpanderp.wam.util.HibernateUtil;

public class ProjectAssignmentDetailDAO {

	public ProjectAssignmentDetail getProjectAssignmentDetail(Long projectAssignmentId) {
		ProjectAssignmentDetail projectAssignmentDetail = null;
		try {
			Session session = HibernateUtil.getSessionFactory().getCurrentSession();
			session.beginTransaction();
			session.setFlushMode(FlushMode.COMMIT);
			Query query = session.createQuery("from ProjectAssignmentDetail pad where pad.projectAssignment.projectAssignmentId = :projectAssignmentId");
			System.out.println(query==null);
			query.setCacheable(false).setLong("projectAssignmentId", projectAssignmentId);
			List list = (List<ProjectAssignmentDetail>) query.list();
			session.getTransaction().commit();
			if(list != null && list.size() > 0){
				projectAssignmentDetail = (ProjectAssignmentDetail) list.get(0);
			}
			return projectAssignmentDetail;
		
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}	}
}
